$(function() {
	var ctxPath =$('body').attr('ctxPath');
	
	$('#btnEnsure').on('click',function(){
		var url = ctxPath+'/basic/detail/about/save?_t='+new Date().getTime();
		var params = $("#form").serialize();
		$.ajax({
			type:'POST',
			url:url,
			data:params,
			dataType:'json',
			success:function(data){
				console.log(data);
				if(data.flag){
					console.log(data.msg);
					window.location.href=ctxPath+'/basic/my/detail/'+data.id+'?_t='+new Date().getTime();
				}else{
					$.toptips(data.msg);
					return;
				}
			},
			error:function(error){
				$.toptips("网络开小差了:(","提示");
				return;
			}
		});
	})
	
// 多图上传
var f2 = document.querySelector('#upload');
f2.onchange = function (e) {
			var files = e.target.files;
			var len = files.length;
			for (var i=0; i < len; i++) {
			    lrz(files[i],{width:640,fieldName:"file"}).then(function (rst) {
			        var xhr = new XMLHttpRequest();
			        xhr.open('POST', ctxPath+'/basic/detail/multiUpload?_t='+new Date().getTime());
			        xhr.onload = function () {
			            if (xhr.status === 200) {
			            var obj = eval('(' + xhr.responseText + ')');
			               $('#img').append('<li  class="weui_uploader_file weui_uploader_status" style="background-image:url('+obj.src+')"><div class="weui_uploader_status_content"></div></li>'); 
			               $('#picInfo').append('<input value="'+obj.picId+'"  type="hidden"  name="picIds" />');
			            } else {
			                // 处理其他情况
			            }
			        };
			        xhr.onerror = function () {
			            // 处理错误
			        };
			        xhr.upload.onprogress = function (e) {
			            // 上传进度
			            var percentComplete = ((e.loaded / e.total) || 0) * 100;
			        };
			        // 添加参数
			        rst.formData.append('size', rst.fileLen);
			        rst.formData.append('base64', rst.base64);
			        // 触发上传
			        
			        xhr.send(rst.formData);
			        
			        return rst;
			    }).catch(function (err) {
			    		alert(err);
			    }).always(function () {// 不管是成功失败，这里都会执行
			    	
			    });
			}// for end
		}
})